package com.yima.baseproj.module.app.pictureBill;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yima.baseproj.module.app.pictureBill.model.PicBillAddModel;
import com.yima.baseproj.module.sys.bill.BillEntity;
import com.yima.baseproj.module.sys.bill.BillService;
import com.yima.baseproj.module.sys.picture.PictureEntity;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class PicBillService extends ServiceImpl<PicBillMapper,PicBillEntity> {

    @Autowired
    private BillService billService;


    /**
     * 新增操作
     * @param pb
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(PicBillAddModel pb){
        int billId = pb.getBillId();
        //获取订单类型, 判断是否入册
        int billType = pb.getBillType();

        //1--电子底片,0--相册
        int putin;
        if(billType==0){
            //1--入册,
            putin = 1;
        }else{
            //仅为电子底片
            putin = 0;
        }
        List<Integer> picIdList = pb.getPictureIdList();
        List<PicBillEntity> pbList = new ArrayList<>();
        for (Integer pId:picIdList) {
            PicBillEntity picBillEntity = new PicBillEntity();
            picBillEntity.setBillId(billId);
            picBillEntity.setPictureId(pId);
            picBillEntity.setPutin(putin);
            pbList.add(picBillEntity);
        }
        //添加pic_bill表
        this.saveBatch(pbList);
        //修改订单状态
        if(billType==0){
            //实体相册状态为待制作
            billService.updateBillPicStatus(billId);
        }else{
            //电子相册为已选择
            billService.updateBillStatus(billId);
        }


    }

    public List<PictureEntity> findPicByBillId(int id){
        return baseMapper.findPicByBillId(id);
    }

    /**
     * 查询图片id列表, 未入册的电子相片
     * @param
     */
    public List<Integer> findBillPicIdFindList(int studentId,int parentId){
        List<Integer> pictureIdList = baseMapper.findPictureIdList(studentId,parentId);
        return pictureIdList;
    }


    /**
     * 查询已经入册的相片
     * @param studentId
     * @param parentId
     * @return
     */
    public List<Integer> findBillPicPutIdFindList(int studentId,int parentId){
        List<Integer> pictureIdList = baseMapper.findPicturePutIdList(studentId,parentId);
        return pictureIdList;
    }


}
